import http
from flask import jsonify
from flask_restful import Api, Resource, reqparse,inputs


# reqparse 数据校验
class Login(Resource):
    def post(self):
        parse = reqparse.RequestParser()
        parse.add_argument("username", required=True, type=str, nullable=True, help="用户名必填", default="")
        parse.add_argument("password", required=True, type=str, nullable=True, help="请输入密码")
        # inputs 校验，url,regex,date,boolean,int_range
        parse.add_argument("int_parm", required=True, type=int,default=0,help="输入数字")
        parse.add_argument("date_parm",required=True, type=inputs.date,help="日期格式")
        parse.add_argument("boolean_parm",required=True,type=inputs.boolean,help="bollean格式")
        parse.add_argument("url_parm",required=True,type=inputs.url,help="url格式")
        parse.add_argument("mobile_parm",required=True,type=inputs.regex("^1\d{10}$"),help="手机号格式不符")
        parse.add_argument("range_parm",required=True,type=inputs.int_range(1,10),help="输入1-10的整数")
        args = parse.parse_args()
        print(args)
        return jsonify({
            "code": http.HTTPStatus.OK,
            "message": "登录成功"
        })
